package cn.umakr.web;

import cn.umakr.entity.Dept;
import cn.umakr.service.DeptService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by wangbo on 2017/7/20.
 */
@WebServlet(name = "UserAddServlet", urlPatterns = "/UserAddServlet")
public class UserAddServlet extends HttpServlet {

    private DeptService deptService = new DeptService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        // 设置request与response的编码
        resp.setContentType("text/html");
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String action = req.getParameter("action");
        if (action.equals("listDept")) {
            //查询所有部门信息
            List<Dept> depts = deptService.findAllDepts();
            req.setAttribute("depts", depts);
            req.getRequestDispatcher("/pages/useradd.jsp").forward(req, resp);
        } else if (action.equals("addUser")) {
            String test = req.getParameter("userdept");
            System.out.println(test);
        }
    }
}
